package tech.yunland.shop.domain.model;

import com.alibaba.fastjson.annotation.JSONField;
import com.moyuer.bsf.domain.model.AbstractEntity;
import com.moyuer.bsf.domain.model.User;

import javax.persistence.*;
import java.util.Date;

/**
 * @author 文卡<wkwenka@gmail.com>  on 17-6-28.
 */
@Entity
@Table(name = "user_member_card")
public class UserMemberCard extends AbstractEntity {

    @ManyToOne
    @JSONField(serialize = false)
    @JoinColumn(name = "member_id")
    private User member;

    @ManyToOne
    @JSONField(serialize = false)
    @JoinColumn(name = "member_card_id")
    private MemberCard memberCard;

    @JSONField(format = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "create_time", nullable = false, insertable = false, updatable = false)
    private Date createTime = new Date();

    private Integer state;

    @Transient
    private String memberId;

    @Transient
    private String memberName;

    @Transient
    private String memberCardId;

    @Transient
    private String memberCardName;

    public User getMember() {
        return member;
    }

    public void setMember(User member) {
        this.member = member;
    }

    public MemberCard getMemberCard() {
        return memberCard;
    }

    public void setMemberCard(MemberCard memberCard) {
        this.memberCard = memberCard;
    }

    public Date getCreateTime() {
        return createTime;
    }

    public void setCreateTime(Date createTime) {
        this.createTime = createTime;
    }

    public Integer getState() {
        return state;
    }

    public void setState(Integer state) {
        this.state = state;
    }

    public String getMemberId() {

        if (this.memberId != null){
            return this.memberId;
        }

        if (this.member != null){
            return this.member.getId();
        }

        return memberId;
    }

    public void setMemberId(String memberId) {
        this.memberId = memberId;
    }

    public String getMemberName() {


        if (this.memberName != null){
            return this.memberName;
        }

        if (this.member != null){
            return this.member.getName();
        }

        return memberName;
    }

    public void setMemberName(String memberName) {
        this.memberName = memberName;
    }

    public String getMemberCardId() {

        if (this.memberCardId != null){
            return this.memberCardId;
        }

        if (this.memberCard != null){
            return this.memberCard.getId();
        }

        return memberCardId;
    }

    public void setMemberCardId(String memberCardId) {
        this.memberCardId = memberCardId;
    }

    public String getMemberCardName() {


        if (this.memberCardName != null){
            return this.memberCardName;
        }

        if (this.memberCard != null){
            return this.memberCard.getName();
        }

        return memberCardName;
    }

    public void setMemberCardName(String memberCardName) {
        this.memberCardName = memberCardName;
    }
}
